package com.cai.piao.project.weight

import android.animation.ObjectAnimator
import android.content.Context
import android.util.AttributeSet
import android.view.animation.AccelerateDecelerateInterpolator
import androidx.appcompat.widget.AppCompatTextView


class RunTextView(context: Context, attrs: AttributeSet) :
    androidx.appcompat.widget.AppCompatTextView(context, attrs) {
    private val duration = 1500
    var number = 0f
        set(number) {
            field = number
            text = String.format("%,.2f", number)
        }

    /**
     * 显示
     * @param number
     */
    fun runWithAnimation(number: Float) {
        val objectAnimator = ObjectAnimator.ofFloat(
            this, "number", 0f, number
        )
        objectAnimator.duration = duration.toLong()
        objectAnimator.interpolator = AccelerateDecelerateInterpolator()
        objectAnimator.start()
    }
}